package com.yswy.domain.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.yswy.domain.common.BasePojo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.zip.CRC32;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("用户设备信息")
@TableName(value = "app_user_device_info")
public class UserDeviceInfo extends BasePojo<UserDeviceInfo> {

    @ApiModelProperty("用户 Id")
    private Long userId ;
    @ApiModelProperty("设备 ID")
    private String deviceId;
    @ApiModelProperty("deviceIdCrc")
    private Long deviceIdCrc ;
    @ApiModelProperty("设备型号")
    private String modelInfo;
    @ApiModelProperty("设备版本号")
    private String versionInfo;
    @ApiModelProperty("系统版本号")
    private String systemInfo;

    @ApiModelProperty("imea")
    private String imei;
    @ApiModelProperty("苹果 Idfa")
    private String idfa;
    @ApiModelProperty("苹果 Idfa")
    private Long idfaCrc;
    @ApiModelProperty("oaid")
    private String oaid ;
    @ApiModelProperty("oaidCrc")
    private Long oaidCrc ;
    @ApiModelProperty("vaid")
    private String vaid ;
    @ApiModelProperty("aaid")
    private String aaid  ;

    @ApiModelProperty("系统 ios  android")
    private String systemDevice = "android";
    @ApiModelProperty("mac")
    private String mac;
    @ApiModelProperty("android_id")
    public String androidId;//android ID
    @ApiModelProperty("is_root")
    public boolean isRoot;//是否root
    @ApiModelProperty("is_adb_enabled")
    public boolean isAdbEnabled;//判断设备 ADB 是否可用
    @ApiModelProperty("sdk_version_code")
    public int sdkVersionCode;//获取设备系统版本码
    @ApiModelProperty("manufacturer")
    public String manufacturer;//厂商
    @ApiModelProperty("is_tablet")
    public boolean isTablet;//是否是平板
    @ApiModelProperty("is_emulator")
    public boolean isEmulator;//否是模拟器

    public UserDeviceInfo(UserDeviceInfo userDeviceInfo) {
        this.userId = userDeviceInfo.getUserId();
        this.deviceId = userDeviceInfo.getDeviceId();
        if (userDeviceInfo.getDeviceId() != null && userDeviceInfo.getDeviceId()!=""){
            CRC32 crc32 = new CRC32();
            crc32.update(userDeviceInfo.getDeviceId().getBytes());
            this.deviceIdCrc  = crc32.getValue();
        }
        this.modelInfo = userDeviceInfo.getModelInfo();
        this.versionInfo = userDeviceInfo.getVersionInfo();
        this.systemInfo = userDeviceInfo.getSystemInfo();
        this.imei = userDeviceInfo.getImei();
        this.idfa = userDeviceInfo.getIdfa();
        if (userDeviceInfo.getIdfa() != null && userDeviceInfo.getIdfa()!=""){
            CRC32 crc32 = new CRC32();
            crc32.update(userDeviceInfo.getIdfa().getBytes());
            this.idfaCrc = crc32.getValue();
        }
        this.oaid = userDeviceInfo.getOaid();
        if (userDeviceInfo.getOaid() != null && userDeviceInfo.getOaid()!=""){
            CRC32 crc32 = new CRC32();
            crc32.update(userDeviceInfo.getOaid().getBytes());
            this.oaidCrc = crc32.getValue();
        }
        this.vaid = userDeviceInfo.getVaid();
        this.aaid = userDeviceInfo.getAaid();
        this.systemDevice = userDeviceInfo.getSystemDevice();
        this.mac = userDeviceInfo.getMac();
        this.androidId = userDeviceInfo.getAndroidId();
        this.sdkVersionCode = userDeviceInfo.getSdkVersionCode();
        this.manufacturer = userDeviceInfo.getManufacturer();
    }
}
